(function(){								
	var updown=function(poster){			
		var self=this;	
		//j this.poster.get(0)相当于form下的第0个元素，此处也为form
		this.poster=poster;	
		//k（this.poster.get(0)).children().eq(3)相当于k下面children方法下的第3个元素，此处为spani
		//l 
		this.id=this.poster.get(0).id;
		this.form=$(this.poster.get(0)).children().eq(0);
		this.up=$($(this.form).children().eq(3)).children().eq(0);
		//form下的第0个对象下的childre方法下的第3个对像下的chlidren方法下的的第0个对象就为up
		//console.log(this.poster);
		this.down=$($(this.form).children().eq(3)).children().eq(1);
		this.inpt=$(this.form).children().eq(2);
		this.but=$(this.poster.get(0)).children().eq(1);
		this.img=$(this.form).children().eq(0);
		this.price=$(this.form).children().eq(1);
		
		var i=1;
		$(this.up).click(function(){
			i++;
			$(self.inpt).val(i);					
		})	
		$(this.down).click(function(){
			if(i>0){
				i--;
				$(self.inpt).val(i);
			}					
		})	
		
		this.goodsCommit();
		
	}
	
	updown.prototype={
		goodsCommit:function(){
			var self=this;
			
			$(self.but).click(function(){
				//ajax提交，异步提交
				var id=self.id;
				var name=$(self.img.get(0)).attr("title");
				var price=$(self.price.get(0)).text().substring(1);
				var num=$(self.inpt.get(0)).val();
				
				console.log(id+","+name+","+price+","+num);
				
				$.ajax({
					type:"post",
					url:"Shopping",
					async:true,
					data:{"id":id,"name":name,"price":price,"num":num},
					success:function(){
						alert("购买成功！");
					}
				});
			})
		}
	}
	
	updown.init=function(posters){
		var _this_=this;
		posters.each(function(i){
			new _this_($(this));
		})
	}
	window["updown"]=updown;
})()
